package com.maykk.Demo03;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassName: Demo03Test
 * @Description: TODO Jdbc 单例模式测试
 * @Author: MaykkStar@163.com
 */
public class Demo03Test {
    public static void main(String[] args) throws SQLException {
        // 实例化工具类
        JdbcUtilsSing jdbc = JdbcUtilsSing.getInstance();
        // 获取连接对象
        Connection conn = jdbc.getConnection();
        // 获取执行 sql 语句对象
        Statement st = conn.createStatement();
        // 写 sql 语句
        String sql = "select id,name,age,score,tel from stu";
        // 执行 sql 语句
        ResultSet rs = st.executeQuery(sql);
        showRes(rs);
        jdbc.free(rs, st, conn);
    }

    private static void showRes(ResultSet rs) throws SQLException {
        while (rs.next()) {
            System.out.println(
                    rs.getInt("id") + " " +
                            rs.getString("name") + " " +
                            rs.getInt("age") + " " +
                            rs.getFloat("score") + " " +
                            rs.getString("tel")
            );
        }
    }
}
